<?php
	defined('_JEXEC') or die('Restricted access');
	require_once(CUTEENGINE_BASE_COMPONENTS_PATH."base_display_component_class.php");
    //
    // t_component_configurator

    //
	class t_component_configurator extends t_base_display_component
	{	
		// property
		// public		
		public $content_loader = null;
		// method
		// protected
		//C
		protected function create_tags_structure()
		{
			global $g_javascript_namespace;            
            
            // javascript
			// C
            //
            if (! $this->main_tag)
			{
                
				$this->main_tag = new t_base_tag(t_base_tag_type::btt_div,$this->name);

				$local_header_script_generator = $this->main_tag->header_script_generator;
				//
                $this->main_tag->include_child_str = true;
                $local_header_script_generator->add_style_sheet_property("#$this->name","display","inline-block");
				$local_header_script_generator->add_style_sheet_property("#$this->name",'position','relative');
				$local_header_script_generator->add_style_sheet_property("#$this->name",'background-color','Lavender');
				$local_header_script_generator->add_style_sheet_property("#$this->name",'border','1px solid blue');
				$this->main_tag->set_editing_tags(true);
                //
				$this->compute_tags_structure();
                if ($this->use_log)
                {
                    $this->main_tag->create_and_add_child_at_bottom(t_base_tag_type::btt_div,parent::get_log_tag_name());
                }    
                /* */
                
			}
		}


		// public
		public function __construct($a_cuteengine_component,$a_query_parameter) 
		{
			global $g_javascript_namespace;
			$this->use_log = true;
			$this->content_loader = new t_content_loader($g_javascript_namespace,$this);
			$this->content_loader->initialize_parameter('undefined',
				'undefined','undefined','undefined',
				'undefined','undefined',false);
			
            parent::__construct($a_cuteengine_component,$a_query_parameter);
			$this->content_loader->component_to_log = $this->get_log_tag_name();
			
		}	
		// C
		public function create_internal_parts()
        {
			global $g_database_namespace;
            parent::create_internal_parts();
			//echo __METHOD__  . "<br>";
			// MAIN FORM
			$local_part = $this->add_new_part(-1,1,t_form_part,'@main_form@','',
				//field 1
				'',
				// action 1
                "@|none|t_action_set_values_into_db|set_info_by_id|".
                ",salva_btn,component,salva_btn,salva_btn,|UPDATE ".$g_database_namespace->main_table_name.
                " SET `ID`=:ID:,`ComponentOrder`=:ComponentOrder:,`cuteengine_instances`=':cuteengine_instances:',`TipoComponente`=':TipoComponente:',`parametri_comuni`=':parametri_comuni:',`parametri_specifici`=':parametri_specifici:',`more_actions`=':more_actions:',`parent_component_id`=:parent_component_id:,`show_on_page`=:show_on_page:,`enabled`=:enabled: WHERE `ID` = :ID:|".
				",id,order,cuteengine_instances,component_type,parametri_comuni,parametri_specifici,more_actions,parent_component_id,show_on_page,enabled,id,|@",1);    
			//
            //FIELDS
			$local_field = $local_part->add_field_from_string('|t_field_text|component|-1|0|Component:|');
            $local_field = $local_part->add_field_from_string('|t_field_lookup|ricerca_componente||-1|');
            $local_field = $local_part->add_field_from_string('|t_field_button|go_btn|-1|->|true|');
            $local_field = $local_part->add_field_from_string('|t_field_text|id|-1|0|ID:|');
			$local_field = $local_part->add_field_from_string('|t_field_text|order|-1|0|ComponentOrder:|');
            $local_field = $local_part->add_field_from_string('|t_field_text|cuteengine_instances|-1|0|cuteengine_instances:|');
			$local_field = $local_part->add_field_from_string('|t_field_text|component_type|-1|0|TipoComponente:|');
			$local_field = $local_part->add_field_from_string('|t_field_text|parametri_comuni|-1|0|parametri_comuni:|');
            $local_field = $local_part->add_field_from_string('|t_field_text|parametri_specifici|-1|0|parametri_specifici:|');
            $local_field = $local_part->add_field_from_string('|t_field_text|more_actions|-1|0|more_actions:|');
            $local_field = $local_part->add_field_from_string('|t_field_text|parent_component_id|-1|0|parent_component_id:|');
            $local_field = $local_part->add_field_from_string('|t_field_text|show_on_page|-1|0|show_on_page:|');            
            $local_field = $local_part->add_field_from_string('|t_field_text|enabled|-1|0|enabled:|');                        
            $local_field = $local_part->add_field_from_string('|t_field_button|salva_btn|-3|Save|true|');	
			// actions
            /*************** list component from db *****************/
            t_base_action::create_action_from_string($this,$local_part,"|none|t_action_list_from_db|get_component|,".
                "component,ricerca_componente,component,go_btn,|SELECT id,TipoComponente from ".$g_database_namespace->main_table_name." WHERE `ID` LIKE ':ID:%'|".
				",id,|,id,TipoComponente,|");

            /**************** get_info_by_id ****************/
   			t_base_action::create_action_from_string($this,$local_part,"|none|t_action_set_values_from_db|get_info_by_id|".
                ",go_btn,component,id,salva_btn,|select id,TipoComponente,ComponentOrder,cuteengine_instances,parametri_comuni,parametri_specifici,more_actions,parent_component_id,show_on_page,enabled from ".$g_database_namespace->main_table_name." WHERE `ID` = :ID:||".
				",id,TipoComponente,ComponentOrder,cuteengine_instances,parametri_comuni,parametri_specifici,more_actions,parent_component_id,show_on_page,enabled,|,id,component_type,order,cuteengine_instances,parametri_comuni,parametri_specifici,more_actions,parent_component_id,show_on_page,enabled,|");            
            // PARTS GRID
           /* $local_part = $this->add_new_part(-2,2,t_table_part,'@parts_grid@','@false@@',
				//field 1
				'',
				// action 1
				"@|none|t_action_set_values_from_db|get_parts_data|,".
                "get_parts_btn,component,parts_grid_tag,,|SELECT * from ".$g_database_namespace->parts_table_name." WHERE `component_id` = :component_id:||".
				",,|,,|@".
				// action 2
				"@",1);   
            $local_field = $local_part->add_field_from_string('|t_field_button|get_parts_btn|-1|Get parts|false|');	
            $local_field = $local_part->add_field_from_string('|t_field_grid|parts_grid_tag|-1|[]|');	*/
            
                   
			
             
        }
		
		//D
	/*	public function display_component()
		{
			parent::display_component();
		}*/
		// E
		public function execute_component_action()
		{
			$local_function = parent::execute_component_action();
            if ($local_function)
			{
				$this->$local_function();
            }
			else
			{
				 
			}
			//echo "argomento: ".$this->url_argument(self::main_url_argument_import_file_name);
			//$this->parse_source();
		}
        
	}
?>